package zr.util;



import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.DailyRollingFileAppender;
import org.apache.log4j.Layout;
import org.apache.log4j.Level;
import org.apache.log4j.SimpleLayout;
import org.apache.log4j.TTCCLayout;
import org.apache.log4j.helpers.DateLayout;

public class Logger {

	private final static org.apache.log4j.Logger logger = org.apache.log4j.Logger
			.getLogger("zr");

	static {
		BasicConfigurator.configure();
		logger.setLevel(Level.INFO);
//		logger.setLevel(Level.DEBUG);
//		logger.setLevel(Level.OFF);
	}

	public static org.apache.log4j.Logger getInstance(Class className) {

		org.apache.log4j.Logger l = org.apache.log4j.Logger
				.getLogger(className);
		if (l.getAppender("日志") == null) {
			org.apache.log4j.DailyRollingFileAppender appender = new DailyRollingFileAppender();
			appender.setName("日志");
			Layout layout=new TTCCLayout();
			appender.setLayout(layout);
			appender.setAppend(true);
			appender.setDatePattern("'.'yyyy-MM-dd");
			appender.setFile("日志.log");
			appender.activateOptions();
			l.addAppender(appender);
		}
		return l;
	}
}
